package com.wizo.csb;

public class Assist {
	public static long getObjectSizeFromString(String size){
		long objectSize = 0;
		int index = -1;
		if((index=size.indexOf("B"))!=-1){
			objectSize = Long.parseLong(size.substring(0, index));
		}else if((index=size.indexOf("K"))!=-1){
			objectSize = (Long.parseLong(size.substring(0, index)))*1024;
		}else if((index=size.indexOf("M"))!=-1){
			objectSize = (Long.parseLong(size.substring(0, index)))*1024*1024;
		}else if((index=size.indexOf("G"))!=-1){
			objectSize = (Long.parseLong(size.substring(0, index)))*1024*1024*1024;
		}else{
			objectSize = 4*1024;
		}
		
		return objectSize;
	}
	
	public static String getObjectSizeFromLong(long size){
		String objectSize = "";
		if(size<1024){
			objectSize = size+"B";
		}else if(size<1024*1024){
			objectSize = (size/1024)+"K";
		}else if(size<1024*1024*1024){
			objectSize = (size/(1024*1024))+"M";
		}else if(size<((long)10)*1024*1024*1024){
			objectSize = (size/(1024*1024*1024))+"G";
		}else{
			objectSize = "4K";
		}
		
		return objectSize;
	}
}
